/*
 * @lc app=leetcode.cn id=95 lang=cpp
 *
 * [95] 不同的二叉搜索树 II
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    vector<TreeNode *> generate(TreeNode* root, TreeNode* left, TreeNode* right)
    {
        return {};
    }
    vector<TreeNode *> generate(int start, int end)
    {
        if (start == end)
        {
            return {new TreeNode(start)};
        }

        vector<TreeNode*> ans;
        for (int i = start; i <= end; i++)
        {
            auto left_v = generate(start, i - 1);
            auto right_v = generate(i + 1, end);
            for (auto l : left_v)
            {
                for (auto r : right_v)
                {
                    auto root = new TreeNode(i);
                    root->left = l;
                    root->right = r;
                    ans.push_back(root);
                }
            }
            if (left_v.size() == 0)
            {
                for (auto r : right_v)
                {
                    auto root = new TreeNode(i);
                    root->right = r;
                    ans.push_back(root);
                }
            }
            if(right_v.size() == 0)
            {
                for(auto l : left_v)
                {
                    auto root = new TreeNode(i);
                    root->left = l;
                    ans.push_back(root);
                }
            }
        }

        return ans;
    }
    vector<TreeNode *> generateTrees(int n)
    {
        if (!n)
            return {};

        return generate(1, n);
    }
};
// @lc code=end
